package com.training.java.redbox.struts.web;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

public class LoginForm  extends ActionForm{
	
	private String username;
	private String password;
	
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}

	
	@Override
	public ActionErrors validate(ActionMapping mapping,
			HttpServletRequest request) {
		System.out.println("i am in login form ");
		
		ActionErrors errors = new ActionErrors();
		
		if(username==null || username.trim().length()==0)
		{
			errors.add(username, new ActionMessage("username.required"));
		}
		if(password==null || password.trim().length()==0)
		{
			errors.add(password, new ActionMessage("password.required"));
		}
		
		System.out.println("i am in login form at the end");
		return errors;
	}
	
}
